package org.ihelpuoo.orm.handler;

import java.lang.reflect.Field;

import org.ihelpuoo.orm.FieldRule;
import org.ihelpuoo.orm.IIIException;
import org.ihelpuoo.orm.ObjectRule;

public class FieldHandlers
{
	private FieldHandler	normalFieldHandler;
	private FieldHandler	listFieldHandler;
	private FieldHandler	arrayFieldHandler;
	private FieldHandler	mapFieldHandler;
	private FieldHandler	objectFieldHandler;

	public FieldHandlers(FieldHandler normalFieldHandler, FieldHandler listFieldHandler,
			FieldHandler arrayFieldHandler, FieldHandler mapFieldHandler,
			FieldHandler objectFieldHandler)
	{
		this.normalFieldHandler = normalFieldHandler;
		this.listFieldHandler = listFieldHandler;
		this.arrayFieldHandler = arrayFieldHandler;
		this.mapFieldHandler = mapFieldHandler;
		this.objectFieldHandler = objectFieldHandler;
	}

	public void process(ObjectRule r, Field f, Object src, Object obj, String prefix)
			throws IIIException
	{
		FieldRule fr = r.getFieldRule(f);
		if (fr.isNormal())
		{
			normalFieldHandler.process(r,f,src,obj,null,null,prefix);
		}
		else if (fr.isArray())
		{
			arrayFieldHandler.process(r,f,src,obj,null,null,prefix);
		}
		else if (fr.isList())
		{
			listFieldHandler.process(r,f,src,obj,null,null,prefix);
		}
		else if (fr.isMap())
		{
			mapFieldHandler.process(r,f,src,obj,null,null,prefix);
		}
		else if (fr.isObject())
		{
			objectFieldHandler.process(r,f,src,obj,null,null,prefix);
		}
		else
		{
		}
	}
}
